package com.iteaj.iot.plc.melsec;

import com.github.xingshuangs.iot.common.buff.ByteReadBuff;
import com.github.xingshuangs.iot.common.buff.EByteBuffFormat;
import com.iteaj.iot.plc.DefaultDataTransfer;

public class MelsecDataTransfer extends DefaultDataTransfer {

    private static MelsecDataTransfer dataTransfer = new MelsecDataTransfer();


    protected MelsecDataTransfer() {
    }

    public static MelsecDataTransfer getInstance() {
        return dataTransfer;
    }

    @Override
    public short toShort(byte[] bytes, int offset) {
        return ByteReadBuff.newInstance(bytes, true).getInt16();
    }


    @Override
    public int toUShort(byte[] bytes, int offset) {
        return ByteReadBuff.newInstance(bytes, true).getUInt16();
    }


    @Override
    public int toInt(byte[] bytes, int offset) {
        return ByteReadBuff.newInstance(bytes, EByteBuffFormat.AB_CD).getInt32();
    }


    @Override
    public long toUInt(byte[] bytes, int offset) {
        return ByteReadBuff.newInstance(bytes, EByteBuffFormat.AB_CD).getUInt32();
    }


    @Override
    public long toLong(byte[] bytes, int offset) {
        return ByteReadBuff.newInstance(bytes, EByteBuffFormat.AB_CD).getInt64();
    }


    @Override
    public float toFloat(byte[] bytes, int offset) {
        return ByteReadBuff.newInstance(bytes, EByteBuffFormat.AB_CD).getFloat32();
    }


    @Override
    public double toDouble(byte[] bytes, int offset) {
        return ByteReadBuff.newInstance(bytes, EByteBuffFormat.AB_CD).getFloat64();
    }

    @Override
    public byte[] byte2Transform(byte[] data, int offset) {
        return data;
    }

    @Override
    public byte[] byte4Transform(byte[] data, int offset) {
        return data;
    }

    @Override
    public byte[] byte8Transform(byte[] data, int offset) {
        return data;
    }
}
